define(['core/boilerplate'],
	function(Boilerplate) {
		var Example = function() {

			this.init = function() {
				// Initialize Example
				this.transform = {
					origin : {
						x : Boilerplate.scene.width/2,
						y : Boilerplate.scene.height/2
					},
					position : {
						x: 0,
						y: 0
					},
					scale : {
						x: 4,
						y: 2
					}
				}

				this.transform._scale = {x:this.transform.scale.x,y:this.transform.scale.y};
				this.transform.scale = Boilerplate.scene.scale(this.transform);

				this.state = "down";
			}
		}

		Example.prototype = {
			name : "Example",
			start : function() {
				this.spriteRenderer = Boilerplate.images.getInstance('plane'); // assuming 'plane.png' is loaded

				this.spriteRenderer.animation = new Boilerplate.images.animation({
				  sWidth : 128,
				  sHeight : 64,
				  sx : 0,
				  sy : 0,
				  animDirection : 'ttb',
				  alternate : true,
				  animByFrame : 12
				});
			},
			update : function() {
				debug('Example is running');

				var coef = this.state === "down" ? 1 : -1,
					limit = percent(Boilerplate.scene.height, 15),
					position = this.getPosition();

				if(this.transform.position.y <= -limit && this.state === "up") {
					this.state = "down";
				}
				if(this.transform.position.y >= limit && this.state === "down") {
					this.state = "up";
				}

				this.transform.position.y = clamp(
					this.transform.position.y + coef, 
					-limit, limit
				);

				// Update Example objects
				this.render();
			},
			render : function() {
				var position = this.getPosition();

				Boilerplate.images.drawImage(
					Boilerplate.scene.ctx,
					this.spriteRenderer,
					position.x, position.y,
					this.transform.scale.x, this.transform.scale.y
				);
			},
			resize : function() {
				this.transform.origin = {
					x : Boilerplate.scene.width/2,
					y : Boilerplate.scene.height/2
				}
			},
			getPosition : function() {
				return {
					x: this.transform.origin.x + this.transform.position.x - this.transform.scale.x/2,
					y: this.transform.origin.y + this.transform.position.y - this.transform.scale.y/2
				};
			}
		}

		return Example;
	}
);